//
//  recommendViewController.m
//  百思不得姐os1
//
//  Created by kqy on 8/2/16.
//  Copyright © 2016 kqy. All rights reserved.
//

#import "recommendViewController.h"
#import "loginRegisterViewController.h"
@interface recommendViewController ()

@end

@implementation recommendViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kqyRandomColor;
    [self setupUI];
}
- (void) setupUI {
//    UIImage *catImageView = [UIImage imageNamed:@"header_cry_icon"];
//    [self.view addSubview:catImageView];
    UIImageView *catImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"header_cry_icon"]];
    [self.view addSubview:catImageView];
    catImageView.translatesAutoresizingMaskIntoConstraints = NO;
    
    UILabel *contentLbl = [[UILabel alloc] init];
    contentLbl.font = [UIFont systemFontOfSize:14];
    contentLbl.textColor = [UIColor blueColor];
    contentLbl.numberOfLines = 0;
    contentLbl.textAlignment = NSTextAlignmentCenter;
    contentLbl.text = @"LabelLine1\nhello goodmorningeveryone\ntheThirdLineIstheTestLastestLongLinecanyouKnowWhatItcanDealWithThis";
    contentLbl.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:contentLbl];
    
    UIButton *loginBtn = [UIButton  buttonWithType:UIButtonTypeCustom];
    [loginBtn setTitle:@"login" forState:UIControlStateNormal];
    [loginBtn setTitle:@"ok" forState:UIControlStateHighlighted];
    [loginBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    [loginBtn setBackgroundImage:[UIImage imageNamed:@"friendsTrend_login"] forState:UIControlStateNormal];
    [loginBtn setBackgroundImage:[UIImage imageNamed:@"friendsTrend_login_click"] forState:UIControlStateHighlighted];
    [loginBtn addTarget:self action:@selector(loginClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:loginBtn];
    loginBtn.translatesAutoresizingMaskIntoConstraints = NO;
    
    NSLayoutConstraint *iconX = [NSLayoutConstraint constraintWithItem:catImageView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0];
    NSLayoutConstraint *iconY = [NSLayoutConstraint constraintWithItem:catImageView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1 constant:0];
    NSLayoutConstraint *iconWidth = [NSLayoutConstraint constraintWithItem:catImageView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:50];
    NSLayoutConstraint *iconHeight = [NSLayoutConstraint constraintWithItem:catImageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:50];
    
    [self.view addConstraint:iconX];
    [self.view addConstraint:iconY];
    [self.view addConstraint:iconWidth];
    [self.view addConstraint:iconHeight];
    
    // 2 content text  constraint
    NSLayoutConstraint *lblTop = [NSLayoutConstraint constraintWithItem:contentLbl attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1 constant:100];
    NSLayoutConstraint *lblX = [NSLayoutConstraint constraintWithItem:contentLbl attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
    NSLayoutConstraint *lblWith = [NSLayoutConstraint constraintWithItem:contentLbl attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:200];
    NSArray *array = [NSArray arrayWithObjects:lblTop,lblX,lblWith, nil];
    [self.view addConstraints:array];
    
    
    //3 button constraint
    NSLayoutConstraint *buttonTop = [NSLayoutConstraint constraintWithItem:loginBtn attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:catImageView attribute:NSLayoutAttributeBottom multiplier:1 constant:90];
    NSLayoutConstraint *buttonWidth = [NSLayoutConstraint constraintWithItem:loginBtn attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:230];
    NSLayoutConstraint *buttonHeight = [NSLayoutConstraint constraintWithItem:loginBtn attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:50];
    NSLayoutConstraint *buttonX = [NSLayoutConstraint constraintWithItem:loginBtn attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
    [self.view addConstraints:[NSArray arrayWithObjects:buttonTop,buttonX,buttonWidth,buttonHeight, nil]];
}

- (void) loginClick {
    loginRegisterViewController *loginRegistVC = [[loginRegisterViewController alloc] init];
    [self presentViewController:loginRegistVC animated:YES completion:nil];
    
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self dismissViewControllerAnimated:YES completion:nil];
}
@end
